<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Proxy Configuration Test</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-section {
            margin: 20px 0;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .result {
            margin-top: 10px;
            padding: 10px;
            border-radius: 3px;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
        }
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <h1>Vite 代理配置测试</h1>
    
    <div class="test-section">
        <h2>当前配置说明</h2>
        <p><strong>前端 baseUrl:</strong> <code>/api/v1</code></p>
        <p><strong>Vite 代理配置:</strong> <code>/api</code> → <code>http://localhost:8000</code></p>
        <p><strong>实际请求路径:</strong> <code>/api/v1/chat/...</code></p>
        <p><strong>代理后的目标:</strong> <code>http://localhost:8000/v1/chat/...</code></p>
    </div>

    <div class="test-section">
        <h2>测试 API 调用</h2>
        <button onclick="testApiCall()">测试 /api/v1/chat/conversation/15/summaries</button>
        <div id="apiResult" class="result"></div>
    </div>

    <div class="test-section">
        <h2>网络请求分析</h2>
        <p>请打开浏览器开发者工具的 Network 标签页，然后点击上面的测试按钮。</p>
        <p>观察请求的实际 URL：</p>
        <ul>
            <li>如果显示 <code>/api/v1/chat/...</code>，说明代理配置生效</li>
            <li>如果显示完整的 <code>http://localhost:8000/...</code>，说明没有使用代理</li>
        </ul>
    </div>

    <script>
        async function testApiCall() {
            const resultDiv = document.getElementById('apiResult');
            resultDiv.innerHTML = '正在测试...';
            resultDiv.className = 'result';
            
            try {
                console.log('发起请求到: /api/v1/chat/conversation/15/summaries');
                
                const response = await fetch('/api/v1/chat/conversation/15/summaries', {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
                
                console.log('响应状态:', response.status);
                console.log('响应头:', response.headers);
                
                if (response.ok) {
                    const data = await response.json();
                    resultDiv.innerHTML = `
                        <strong>✅ 请求成功!</strong><br>
                        状态码: ${response.status}<br>
                        响应数据: <pre>${JSON.stringify(data, null, 2)}</pre>
                    `;
                    resultDiv.className = 'result success';
                } else {
                    const errorText = await response.text();
                    resultDiv.innerHTML = `
                        <strong>⚠️ 请求失败</strong><br>
                        状态码: ${response.status}<br>
                        错误信息: ${errorText}
                    `;
                    resultDiv.className = 'result error';
                }
            } catch (error) {
                console.error('请求错误:', error);
                resultDiv.innerHTML = `
                    <strong>❌ 网络错误</strong><br>
                    错误信息: ${error.message}<br>
                    <small>这可能表示后端服务未启动或代理配置有问题</small>
                `;
                resultDiv.className = 'result error';
            }
        }
        
        // 页面加载时显示当前 URL 信息
        window.addEventListener('load', function() {
            console.log('当前页面 URL:', window.location.href);
            console.log('当前域名:', window.location.origin);
        });
    </script>
</body>
</html>